﻿
Imports std

Public Class scriptapp
    Inherits app

    Protected Sub New(ByVal ifuncs As vector(Of [function]))
        MyBase.New(ifuncs)
    End Sub

    Protected Shared Shadows Function parseImpl(ByVal script As String, _
                                                ByRef output As vector(Of [function])) As Boolean
        Dim input As String = Nothing
        If Not readfile(script, input) Then
            raiseError("cannot read content from script file " + script, errorHandle.errorType.warning)
            Return False
        End If

        Return app.parseImpl(input, 0, output)
    End Function

    Protected Shared Shadows Function parseImpl(ByVal script As String, ByRef __NOT_IN_USE__ As Int64, _
                                                ByRef output As scriptapp) As Boolean
        Dim funcs As vector(Of [function]) = Nothing
        If parseImpl(script, funcs) Then
            output = New scriptapp(funcs)
            Return True
        Else
            Return False
        End If
    End Function

    Protected Overrides Sub setsource(ByVal script As String, ByVal start As Long, ByVal [end] As Long)
        setsourceImpl(script, start, [end])
    End Sub

    Public Shared Shadows Function parse(ByVal script As String, ByRef output As scriptapp) As Boolean
        Return parsebase(script, 0, output, AddressOf parseImpl)
    End Function
End Class
